﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Threading.Tasks;
using System.Windows;
using System.Collections.Generic;
using INTEX.SCHEDULER;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TRSAV33
    {   
      
        public TRSAV33()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_MKRF(); 
            DataContext = MV;
            IsAV = true;
            zAV33Height = 600;
            MESSAGES += "SSHOWGANT;"; 
            InitializeComponent();
            TMV.Scheduler = new YDAPS();
            TMV.SetUpAV33();
            if (app.User == "ITXV    ")
            {
                //   LFD = "026058";
            }
        } 

        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            try
            {
                MessageInfo msg = e.Info;
                string task = msg.MSGTYPE;
                switch (task)
                {
                    case "SSHOWGANT":
                        if (zAV33Height >= 500)
                            zAV33Height = 400;
                        break;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void ReSetTab()
        {
            IsAV = false;
            IsSP = false;
        }

        public override void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            base.bgWorker_RunWorkerCompleted(sender, e);
            vwMaster.View.MoveCurrentTo(-1);
            EventDispatcher.Instance.RaiseStatus("数据查询完成", StatusEventType.StopProgress);
        }
        bool IsLoadMK = false;

        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            base.bgWorker_DoWork(sender, e);
            EventDispatcher.Instance.RaiseStatus("开始查询", StatusEventType.RunningProgress);
            if (IsLoadMK)
            {
                LoadMKRF(PM);
                return;
            }

        }
 
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            IsLoadMK = true;
            PM["KSTKRS"] = KSTKRS;
            PM["KST"] = KST;
            PM["AGANG"] = AGANG;
            PM["MKFERLKZ"] = " ";
            bgWorker.RunWorkerAsync();
            base.QueryCommand(sender, e);
        }
        private void LoadMKRF(Dictionary<string, object> pm)
        {
            TMV.VKK.UVKK04(null);
            dwData = TBMain.NewRow();
            dwData["ABFMANDANT"] = app.Mandant;
            dwData["ABFKSTKRS"] = pm["KSTKRS"].ToString();
            dwData["ABFKST"] = pm["KST"].ToString();
            dwData["ABFAGANG"] = pm["AGANG"].ToString();
            dwData["MKFERLKZ"] = pm["MKFERLKZ"].ToString();
            SResult = TMV.QTMKRF03(dwData);
            TMV.MergeData(SResult, true, true);
        }

        private void StartScheduleCommand(object sender, RoutedEventArgs e)
        {
            TMV.VKK.UVKK04(null);

            TMV.RSSchedule(KSTKRS, KST, AMTYP, LFD,AGANG);
        } 

        private void ShowDetailCommand(object sender, RoutedEventArgs e)
        {
            TMV.ShowDetail(dwMKRF);
        }

        private void RefreshCommand(object sender, RoutedEventArgs e)
        {

        } 
    }
}
